package cn.ymatrix.jdbcToYMatrix.oracleToYMatrix;

import cn.ymatrix.utils.Config;

import java.sql.*;

public class ReadOracleTOMxgate {

  public static void main(String[] args) throws ClassNotFoundException {
    Class.forName(Config.getOracleDriverName());
    try (Connection connection =
        DriverManager.getConnection(
            Config.getOracleURL(), Config.getOracleName(), Config.getOraclePassword())) {
      // long startTime = System.currentTimeMillis();
      PreparedStatement preparedStatement = connection.prepareStatement(Config.getOracleQuery());
      ResultSet resultSet = preparedStatement.executeQuery();
      int columnCount = resultSet.getMetaData().getColumnCount();
      StringBuilder str;
      while (resultSet.next()) {
        str = new StringBuilder();
        for (int i = 1; i <= columnCount; i++) {
          str.append(resultSet.getObject(i) + Config.getDelimiter());
        }
        System.out.println(str.deleteCharAt(str.length() - 1));
      }
      // long endTime = System.currentTimeMillis();
      // double elapsedSeconds = (endTime - startTime) / 1000.0;
      // System.out.println("总耗时: " + elapsedSeconds + " seconds");
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
}
